<?php
	namespace Common\Logic;
	use Common\Model\CourseModel;
	class CourseLogic extends CourseModel{
		/*
		* Function:		getCourseList
		* Description:	课程列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getCourseList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getCourseFilter($filter);
			return $this->where($conditon)->order('sort desc,id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getCourseFilter
		* Description:	课程列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getCourseFilter($filter = ''){
			$conditon = array();
			if(!empty($filter['title'])){
				$conditon['name'] = array('like','%'.$filter['title'].'%');
			}
			if(!empty($filter['store_id'])){
			    $conditon['store_id'] = $filter['store_id'];
			}
            if(!empty($filter['coach_id'])){
                $conditon['coach_id'] = $filter['coach_id'];
            }
            if(!empty($filter['cate_id'])){
                $conditon['cate_id'] = $filter['cate_id'];
            }
            if(!empty($filter['course_date'])){
                $conditon['course_date'] = $filter['course_date'];
            }
			return $conditon;
		}
		
		/*
		* Function:get:	getCourseCount
		* Description:	课程列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getCourseCount($filter = ''){
			$conditon = $this->getCourseFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addCourse
		* Description:	增加课程
		* @param:		$data array 增加的数组
		*/
		public function addCourse($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getCourseInfo
		* Description:	获取课程信息 by row
		* @param:		$id int ID
		*/
		public function getCourseInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateCourse
		* Description:	更新课程
		* @param:		$data array 更新的数组
		*/
		public function updateCourse($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteCourse
		* Description:	删除课程
		* @param:		$id int ID
		*/
		public function deleteCourse($id){
			return $this->where(array('id'=>$id))->delete();
		}
		
		/*
		* Function:		getCourseAllList
		* Description:	部门列表
		*/
		public function getCourseAllList(){
			return $this->where(array('status'=>1))->select();
		}
	}
?>